package com.data.modules.online.auth.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;

import com.data.common.system.vo.LoginUser;
import com.data.modules.online.auth.entity.OnlAuthPage;
import com.data.modules.online.auth.entity.OnlAuthRelation;
import com.data.modules.online.auth.mapper.OnlAuthPageMapper;
import com.data.modules.online.auth.mapper.OnlAuthRelationMapper;
import com.data.modules.online.auth.service.IOnlAuthPageService;
import com.data.modules.online.auth.vo.AuthColumnVO;
import com.data.modules.online.auth.vo.AuthPageVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@SuppressWarnings("ALL")
@Slf4j
@Service
public class OnlAuthPageServiceImpl extends ServiceImpl<OnlAuthPageMapper, OnlAuthPage> implements IOnlAuthPageService {
    @Autowired
    private OnlAuthRelationMapper onlAuthRelationMapper;

    private static /* synthetic */ java.lang.Object m31a(java.lang.invoke.SerializedLambda r4) {
        /*
        // Method dump skipped, instructions count: 1364
        */
        throw new UnsupportedOperationException("Method not decompiled: com.data.modules.online.auth.service.p004a.OnlAuthPageServiceImpl.m31a(java.lang.invoke.SerializedLambda):java.lang.Object");
    }

    /*  JADX ERROR: MOVE_RESULT instruction can be used only in fallback mode
        jadx.core.utils.exceptions.CodegenException: MOVE_RESULT instruction can be used only in fallback mode
        */


    @Override
    public void switchAuthColumn(AuthColumnVO authColumnVO) {
        String cgformId = authColumnVO.getCgformId();
        String code = authColumnVO.getCode();
        int switchFlag = authColumnVO.getSwitchFlag();
        if (switchFlag == 1) {
            switchListShow(cgformId, code, authColumnVO.isListShow());
        } else if (switchFlag == 2) {
            switchFormShow(cgformId, code, authColumnVO.isFormShow());
        } else if (switchFlag == 3) {
            switchFormEditable(cgformId, code, authColumnVO.isFormEditable());
        }
    }

    @Override
    @Transactional
    public void switchFormShow(String cgformId, String code, boolean flag) {
        m32a(cgformId, code, 5, 5, flag);
    }

    @Override
    @Transactional
    public void switchFormEditable(String cgformId, String code, boolean flag) {
        m32a(cgformId, code, 3, 5, flag);
    }

    @Override
    @Transactional
    public void switchListShow(String cgformId, String code, boolean flag) {
        m32a(cgformId, code, 5, 3, flag);
    }

    @Override
    public List<AuthPageVO> queryRoleAuthByFormId(String roleId, String cgformId, int type) {
        return this.baseMapper.queryRoleAuthByFormId(roleId, cgformId, type);
    }

    @Override
    public List<AuthPageVO> queryRoleDataAuth(String roleId, String cgformId) {
        return this.baseMapper.queryRoleDataAuth(roleId, cgformId);
    }

    @Override
    public void disableAuthColumn(AuthColumnVO authColumnVO) {

    }

    @Override
    public void enableAuthColumn(AuthColumnVO authColumnVO) {

    }

    @Override
    public List<AuthPageVO> queryAuthByFormId(String cgformId, int type) {
        if (type == 1) {
            return this.baseMapper.queryAuthColumnByFormId(cgformId);
        }
        return this.baseMapper.queryAuthButtonByFormId(cgformId);
    }

    @Override
    public List<String> queryRoleNoAuthCode(String cgformId, Integer control, Integer page) {
        return this.baseMapper.queryRoleNoAuthCode(((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId(), cgformId, control, page, null);
    }

    @Override
    public List<String> queryFormDisabledCode(String cgformId) {
        return queryRoleNoAuthCode(cgformId, 3, 5);
    }

    @Override
    public List<String> queryHideCode(String userId, String cgformId, boolean isList) {
        int i = 5;
        OnlAuthPageMapper onlAuthPageMapper = this.baseMapper;
        if (isList) {
            i = 3;
        }
        return onlAuthPageMapper.queryRoleNoAuthCode(userId, cgformId, 5, Integer.valueOf(i), null);
    }

    @Override
    public List<String> queryListHideColumn(String userId, String cgformId) {
        return this.baseMapper.queryRoleNoAuthCode(userId, cgformId, 5, 3, 1);
    }

    @Override
    public List<String> queryFormHideColumn(String userId, String cgformId) {
        return this.baseMapper.queryRoleNoAuthCode(userId, cgformId, 5, 5, 1);
    }

    @Override
    public List<String> queryFormHideButton(String userId, String cgformId) {
        return this.baseMapper.queryRoleNoAuthCode(userId, cgformId, 5, 5, 2);
    }

    @Override
    public List<String> queryHideCode(String cgformId, boolean isList) {
        int i = 5;
        String id = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId();
        OnlAuthPageMapper onlAuthPageMapper = this.baseMapper;
        if (isList) {
            i = 3;
        }
        return onlAuthPageMapper.queryRoleNoAuthCode(id, cgformId, 5, Integer.valueOf(i), null);
    }

    @Override
    public List<String> queryListHideButton(String userId, String cgformId) {
        if (userId == null) {
            userId = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getId();
        }
        return this.baseMapper.queryRoleNoAuthCode(userId, cgformId, 5, 3, 2);
    }



private void m32a(String var1, String var2, int var3, int var4, boolean var5) {
        LambdaQueryWrapper<OnlAuthPage> var6 = new LambdaQueryWrapper<OnlAuthPage>();
        var6.eq(OnlAuthPage::getCgformId, var1);
        var6.eq(OnlAuthPage::getCode, var2);
        var6.eq(OnlAuthPage::getControl, var3);
        var6.eq(OnlAuthPage::getPage, var4);
        var6.eq(OnlAuthPage::getType, 1);
        OnlAuthPage var7 = (OnlAuthPage)((OnlAuthPageMapper)this.baseMapper).selectOne(var6);
        if (var5) {
            if (var7 == null) {
                OnlAuthPage var8 = new OnlAuthPage();
                var8.setCgformId(var1);
                var8.setCode(var2);
                var8.setControl(var3);
                var8.setPage(var4);
                var8.setType(1);
                var8.setStatus(1);
                ((OnlAuthPageMapper)this.baseMapper).insert(var8);
            } else if (var7.getStatus() == 0) {
                var7.setStatus(1);
                ((OnlAuthPageMapper)this.baseMapper).updateById(var7);
            }
        } else if (!var5 && var7 != null) {
            String var9 = var7.getId();
            ((OnlAuthPageMapper)this.baseMapper).deleteById(var9);
            this.onlAuthRelationMapper.delete((Wrapper)(new LambdaQueryWrapper<OnlAuthRelation>()).eq(OnlAuthRelation::getAuthId, var9));
        }
    }
}